package main

import (
	"math"
	"sort"
)

func minMoves2(nums []int) int {
	N := len(nums)
	sort.Ints(nums)
	midNum := nums[N/2]
	res := 0
	for i := 0; i < N; i++ {
		res += int(math.Abs(float64(nums[i] - midNum)))
	}
	return res
}
